/**
 * @param {number[]} costs
 * @param {number} coins
 * @return {number}
 */
/**输入：costs = [1,3,2,4,1], coins = 7
 * 他想要买尽可能多的雪糕。
输出：4
解释：Tony 可以买下标为 0、1、2、4 的雪糕，总价为 1 + 3 + 2 + 1 = 7 */
 var maxIceCream = function(costs, coins) {
    // console.log(costs,coins);
    let a = costs.sort((a, b) => a - b)
    let count = 0

    console.log('a',a);
    for (let i = 0; i <= a.length; i++) {
        console.log(i);
        if (coins >= a[i]) {
            coins = coins - a[i]
            count ++
        } else {
            return  count
        }
    }
    return a.length

};
let res = maxIceCream(costs = [1,3,2,4,1], coins = 7)
console.log('res->',  res);